<template>
	<view class="main">
		<image src="http://shop.outletds.com/img/bg.png" mode="aspectFill" class="bg"></image>
		<nav-bar title="专属权益"/>
		<u-tabs :list="tabs" active-color="#CB712B" :current="current" @change="changeTab" class="tabs"></u-tabs>
		<view class="card">
			<view class="header">
				<view class="title">{{detail.card_title}}</view>
				<view class="hint">{{detail.card_desc}}</view>
				<image :src="detail.backgroud_image" mode="aspectFill" class="bg"></image>
			</view>
			<view class="content">
				<u-parse :html="detail.content"></u-parse>
			</view>
		</view>
		<view class="confirm">
			<view class="btn" @click="goBack">立即开通付费会员</view>
		</view>
	</view>
</template>

<script>
	import {vipInfoAPi} from '@/api/my.js'
	export default {
		data() {
			return {
				current: 0,
				tabs: [],
				content: "<h1>123456</h1>",
				type: 0,
				id: '',
				details: []
			}
		},
		computed:{
			detail(){
				if(this.details.length < 1)return {}
				let data = this.details.interest
				let info = data[this.current]
				return info
			}
		},
		onLoad(opt) {
			// 0-会员 1-合伙人
			this.type = opt.type || 0
			this.id = opt.id || 0
			this.getData()
		},
		methods: {
			changeTab(index){
				this.current = index
			},
			async getData(){
				let {data} = await vipInfoAPi()
				console.log(data);
				this.tabs = data[this.type].interest.map(item=>{
					return {
						id: item.id,
						name: item.card_title
					}
				})
				this.details = data[this.type]
				// 查询跳转
				if(this.id){
					const index = this.details.interest.findIndex(item=>item.id == this.id)
					this.current = index
				}
			},
			goBack(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	page{
		background-color: #eee;
	}
.confirm{
	width: 100%;
	position: fixed;
	left: 0;
	bottom: 0;
	background-color: #fff;
	padding: 20rpx;
	padding-bottom: 50rpx;
	box-sizing: border-box;
	.btn{
		background-color: #FF9403;
		@extend .flex-center;
		padding: 25rpx;
		font-size: 32rpx;
		color: #FFF;
		border-radius: 100rpx;
	}
}
.tabs{
	position: relative;
	z-index: 100;
}
.card{
	background-color: #fff;
	margin: 40rpx;
	border-radius: 20rpx;
	overflow: hidden;
	overflow-y: scroll;
	height: calc(100vh - 500rpx);
	position: relative;
	z-index: 100;
	.content{
		padding: 20rpx;
	}
	.header{
		position: relative;
		padding: 40rpx 30rpx;
		height: 200rpx;
		width: 100%;
		box-sizing: border-box;
		.title{
			color: #A66A00;
			font-size: 40rpx;
			font-weight: bold;
			position: relative;
			margin-bottom: 20rpx;
			z-index: 10;
		}
		.hint{
			color: #DBB56F;
			font-size: 30rpx;
			position: relative;
			z-index: 10;
		}
		.bg{
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100px;
		}
	}
}
.bg{
	position: fixed;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
}
</style>
